<?php
/**
 * Created by PhpStorm.
 * Author: ExtraXue
 * Date: 2018/5/9
 * Description:
 */
error_reporting(E_ALL^E_NOTICE);
?>

<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" href="css/pintuer.css">
    <link rel="stylesheet" href="css/admin.css">
    <script src="js/jquery.js"></script>
    <script src="js/pintuer.js"></script>
    <title>用户党支部信息修改</title>
</head>
<body>
<div class="panel admin-panel">
    <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>用户党支部信息修改</strong></div>
    <div class="body-content">
        <form method="post" class="form-x" action="relDeptUserChange.php">
            <div class="form-group" style="margin-top: 30px;">
                <div class="label">
                    <label>查询关键字：</label>
                </div>
                <div class="field">
                    <select class="input" name="searchKind" style="width: 200px" ">
                    <!--                    <option value=" ">请选择...</option>-->
                    <option value="number">用户学号/工号</option>
                    </select>
                </div>
            </div>
            <?php
            session_start();
            $_SESSION['keyWord']=$keyWord;
            ?>
            <div style="height: 20px"></div>
            <div class="form-group">
                <div class="label">
                    <label>关键字:</label>
                </div>
                <div class="field">
                    <input type="text" class="input" name="keyWord" size="50" placeholder="请输入学号/工号进行查询"
                           style="width:200px"/>
                    <div class="field" style="padding-top: 20px;">
                        <button class="button bg-main icon-check-square-o" type="submit">提交</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<?php

require_once('pdo.php');
$searchKind = $_POST['searchKind'];
$keyWord = $_POST['keyWord'];
$_SESSION['keyWord']=$keyWord;

if ($searchKind == 'number') {
    $sqlSearchUserInfo = "select * from user_info a where a.number = '{$keyWord}'";
    $rsSearchUserInfo = $pdo->query($sqlSearchUserInfo);
    $resultSearchUserInfo = $rsSearchUserInfo->fetch(PDO::FETCH_ASSOC);

    $get_dept = "select * from dept_info where dept_id='{$resultSearchUserInfo['dept_id']}'";
    $rs_dept = $pdo->query($get_dept);
    $result_dept = $rs_dept->fetch(PDO::FETCH_ASSOC);

    $sqlGetDeptInfo="select * from dept_info";
    $rsSGetDeptInfo=$pdo->query($sqlGetDeptInfo);
    $resultGetDeptInfo=$rsSGetDeptInfo->fetch(PDO::FETCH_ASSOC);

    foreach ($pdo->query($sqlSearchUserInfo) as $key => $resultSearchUserInfo) {
        ?>

        <div style="height: 20px;"></div>

        <div class="dialog open">
            <div class="dialog-head">
                <h3 style="color: #C50C11">用户ID：<?php echo "$resultSearchUserInfo[id]" ?></h3>
            </div>
            <form method="get" action="relDeptUserChangeCheck.php" id="search_form1">
                <div class="dialog-body">
                    <p>
                    <h3><strong>用户名称：</strong><?php echo "$resultSearchUserInfo[username]" ?>
                        <a class="button button-little bg-green" style="padding: 5px 10px;margin-left: 10px;cursor: pointer;" onclick="document.getElementById('newName').style.display='inline'">
                            <span class="">修改</span></a>
                        <div style="display: none;" id="newName">
                            &nbsp;→ &nbsp;
                            <input type="text" class="input" name="newName"
                                   style="width:150px;display: inline;"/>
                            <a class="button button-little bg-yellow" style="padding: 5px 10px;margin-left: 10px;cursor: pointer;" onclick="document:search_form1.submit();">
                                <span>提交</span></a>
                        </div>
                    </h3></p>
                    <p><h3><strong>用户学号/工号：</strong><?php echo "$resultSearchUserInfo[number]" ?>
                        <a  class="button button-little bg-green" style="padding: 5px 10px;margin-left: 10px;cursor: pointer;" onclick="document.getElementById('newNumber').style.display='inline'">
                            修改</a>
                        <div style="display: none;" id="newNumber">
                            &nbsp;→ &nbsp;
                            <input type="text" class="input" name="newNumber"
                                   style="width:150px;display: inline;"/>
                            <a class="button button-little bg-yellow" style="padding: 5px 10px;margin-left: 10px;cursor: pointer;" onclick="document:search_form1.submit();">
                                <span>提交</span></a>
                        </div>
                    </h3></p>
                    <p>
                    <h3><strong>所在党支部：</strong><?php echo "$result_dept[dept_name]" ?>
                        <a class="button button-little bg-green" style="padding: 5px 10px;margin-left: 10px;cursor: pointer;" onclick="document.getElementById('newDept').style.display='inline'">
                            <span class="">修改</span></a>
                        <div style="display: none;" id="newDept">
                            &nbsp;→ &nbsp;
                            <select name="newDept" id="newDept" class="input" STYLE="width: 200px;display: inline-block">
                                <?php
                                foreach ($pdo->query($sqlGetDeptInfo) as $key => $resultGetDeptInfo){
                                    ?>
                                    <option value=<?php echo "$resultGetDeptInfo[dept_id]"?>><?php echo "$resultGetDeptInfo[dept_name]"?></option>
                                    <?php
                                }
                                ?>
                            </select>
                            <a class="button button-little bg-yellow" style="padding: 5px 10px;margin-left: 10px;cursor: pointer;" onclick="document:search_form1.submit();">
                                <span>提交</span></a>
                        </div>
                    </h3></p>
                </div>
            </form>

        </div>
        <?php
    }?>

    <?php
}
if ($keyWord && !$resultSearchUserInfo) {
    ?>
    <p></p>
    <div class="alert alert-red">
        <span class="close"></span><strong>注意：</strong>未查询到此用户信息</div>

    <?php
}
?>

</body>
</html>
